//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#pragma package(smart_init)
#pragma resource "*.dfm"
//---------------------------------------------------------------------------
#include "vCSupprLogMenu.h"
//---------------------------------------------------------------------------
//                         Constructeur
//---------------------------------------------------------------------------
__fastcall TvSSupprLogMenu::TvSSupprLogMenu(TComponent* Owner)
    : TForm(Owner)
{
    TZZMySqlQuery * MaRequete = NULL;
    try{
        dmWebHelp = new TdmWebHelp((TComponent*)0);
        lText->Caption = MSG_LOG;

        MaRequete = new TZZMySqlQuery( (TComponent*)0);
        MaRequete->Database = dmWebHelp->dbWebHelp;

        MaRequete->Sql->Text =  "select logiciels.log_nom, logiciels.log_code "
                                "from logiciels "
                                    "left outer join versions on (logiciels.log_code=versions.log_code) "
                                "where versions.log_code is null";
        MaRequete->Open();
        MaRequete->First();

        if(!MaRequete->Eof) {
            while(!MaRequete->Eof) {
                cbLogiciel->Items->AddObject( asRequete(0), (TObject*)nRequete(1) );
                MaRequete->Next();
            }
            cbLogiciel->Enabled = true;;
        }else {
            cbLogiciel->Items->Add(AUCUN_LOGICIEL);
            cbLogiciel->ItemIndex = 0;
            cbLogiciel->Enabled = false;
        }

        MaRequete->Sql->Clear();
        MaRequete->Close();


    }catch( Exception &e ) {
        EIC_DISPLAY_EXCEPTION(e);}
    if(MaRequete) {delete MaRequete; MaRequete = NULL;}
}
//---------------------------------------------------------------------------
__fastcall TvSSupprLogMenu::~TvSSupprLogMenu()
{
    try {
        if(dmWebHelp) {delete dmWebHelp; dmWebHelp = NULL;}
    }catch( Exception &e ) {
        EIC_DISPLAY_EXCEPTION(e);}
}
//---------------------------------------------------------------------------
//                     Supprimer un logiciel
//---------------------------------------------------------------------------
void __fastcall TvSSupprLogMenu::Supprimer( void )
{
    TZZMySqlQuery * MaRequete = NULL;
    try{

        MaRequete = new TZZMySqlQuery( (TComponent*)0);
        MaRequete->Database = dmWebHelp->dbWebHelp;

        //Insertion dans la table référence
        //---------------------------------
        MaRequete->Sql->Text =  (AnsiString)"delete from logiciels where log_code = "+(int)cbLogiciel->Items->Objects[cbLogiciel->ItemIndex];
        MaRequete->ExecSql();
        MaRequete->Sql->Clear();

        MaRequete->Sql->Text = "Commit"; 
        MaRequete->ExecSql();
        MaRequete->Sql->Clear();

        MaRequete->Close();


    }catch( Exception &e ) {
        EIC_DISPLAY_EXCEPTION(e);}
    if(MaRequete) {delete MaRequete; MaRequete = NULL;}
}
//---------------------------------------------------------------------------
//                  Valider la suppression
//---------------------------------------------------------------------------
void __fastcall TvSSupprLogMenu::bbOkClick(TObject *Sender)
{
    CHistorique * Hist = NULL;
    try{
        if(cbLogiciel->Text != AUCUN_LOGICIEL ) {
            if(cbLogiciel->ItemIndex != AUCUNE_SELECTION){
                if(cbLogiciel->Items->Strings[0] != AUCUN_LOGICIEL)
                    Supprimer();
                ModalResult = mrOk;

                Hist = new CHistorique();
                Hist->AjouterOperation( Histo_SUPPR_LOG, cbLogiciel->Items->Strings[cbLogiciel->ItemIndex] );

            }else {
                MessageDlg("Veuillez sélectionner un logiciel à supprimer.", mtWarning, TMsgDlgButtons() << mbOK, 0);
                ModalResult = mrNone;
            }
        }else {
            MessageDlg("Aucun logiciel à supprimer.", mtWarning, TMsgDlgButtons() << mbOK, 0);
            ModalResult = mrNone;
        }
    }catch( Exception &e ) {
        EIC_DISPLAY_EXCEPTION(e);}
    if(Hist) {delete Hist; Hist = NULL;}
}
//---------------------------------------------------------------------------

